import Vue from 'vue'
import Router from 'vue-router'
import Store from './store'
import Home from './views/Home.vue'
import Test from './views/Test.vue'
import SignInUp from './views/SignInUp.vue'
import Admin from './views/admin/Admin'
import AdminCheck from './views/admin/AdminCheck'
import Teacher from './views/teacher/Teacher'
import TeacherTopic from './views/teacher/TeacherTopic'
import TeacherChoice from './views/teacher/TeacherChoice'
import TeacherChoiceDetail from './views/teacher/TeacherChoiceDetail'
import TeacherComment from './views/teacher/TeacherComment'
import TeacherCommentDetail from './views/teacher/TeacherCommentDetail'
import Student from './views/student/Student'
import StudentChoice from './views/student/StudentChoice'
import StudentTopic from './views/student/StudentTopic'

Vue.use(Router)

export default new Router({
  routes: [{
    path: '/',
    name: 'home',
    component: Home,
    beforeEnter: (to, from, next) => {
      // 通过 vuex 获取当前 user 是否登录
      if (Store.getters.getUser) {
        next()
      } else {
        next({ path: '/sign-in-up' })
      }
    },
    children: [
      { path: '/admin', name: 'admin', component: Admin },
      { path: '/admin/check', name: 'admin-check', component: AdminCheck },
      { path: '/teacher', name: 'teacher', component: Teacher },
      { path: '/teacher/topic', name: 'teacher-topic', component: TeacherTopic },
      { path: '/teacher/choice', name: 'teacher-choice', component: TeacherChoice },
      { path: '/teacher/choice/:id', name: 'teacher-choice-detail', component: TeacherChoiceDetail },
      { path: '/teacher/comment', name: 'teacher-comment', component: TeacherComment },
      { path: '/teacher/comment/:comNo', name: 'teacher-comment-detail', component: TeacherCommentDetail },
      { path: '/student', name: 'student', component: Student },
      { path: '/student/choice', name: 'student-choice', component: StudentChoice },
      { path: '/student/topic', name: 'student-topic', component: StudentTopic }
    ]
  }, {
    path: '/sign-in-up',
    name: 'sign-in-up',
    component: SignInUp
  }, {
    path: '/test',
    name: 'test',
    component: Test
  }]
})
